package com.zhida.smartcontrol.dialog.devicelistdialog;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import com.jay.tools.recycler.MultipleViewHolder;
import com.jay.tools.recycler.SingleRecyclerAdapter;
import com.jay.tools.utils.ResUtil;
import com.zhida.smartcontrol.R;
import com.zhida.smartcontrol.pagectrl.ProjectListBean;

import java.util.List;

public class DeviceListAdapter extends SingleRecyclerAdapter<ProjectListBean> {
    private int mBlack, mGray;

    public DeviceListAdapter(@Nullable List<ProjectListBean> data) {
        super(R.layout.dialog_common_item, data);
    }

    @Override
    public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
        super.onAttachedToRecyclerView(recyclerView);
        Context context = recyclerView.getContext();
        mBlack = ResUtil.getColor(context, R.color.c_333333);
        mGray = ResUtil.getColor(context, R.color.c_CCCCCC);
    }

    @Override
    protected void convert(MultipleViewHolder holder, ProjectListBean info) {
        TextView tvItem = holder.getView(R.id.tv_item);

        tvItem.setText(info.getProjectName());

        if (mPosition == holder.getAdapterPosition()) {
            tvItem.setTextColor(mBlack);
        } else {
            tvItem.setTextColor(mGray);
        }

        tvItem.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != mListener) {
                    mListener.onClick(info, 0);
                    setPosition(holder.getAdapterPosition());
                }
            }
        });
    }


}
